package arena;

import java.awt.Canvas;
import java.awt.Point;

import arena.entity.CheckPoint;
import arena.entity.EntityFactory;
import arena.entity.SwordItem;
import arena.entity.Wall;
import arena.base.ArenaMoveBlockers;
import arena.base.ArenaOverlapRules;
import arena.base.MonsterMovableDriver;
import arena.soldier.ArmedUnitSoldier;
import arena.soldier.ArmedUnitSquad;
import arena.soldier.HeroMan;
import arena.soldier.SoldierGame;
import arena.utils.AgeFactory;
import arena.utils.ArenaAgeFactory;
import gameframework.base.MoveStrategyRandom;
import gameframework.game.CanvasDefaultImpl;
import gameframework.game.Game;
import gameframework.game.GameLevelDefaultImpl;
import gameframework.game.GameMovableDriverDefaultImpl;
import gameframework.game.GameUniverseDefaultImpl;
import gameframework.game.GameUniverseViewPortDefaultImpl;
import gameframework.game.MoveBlockerChecker;
import gameframework.game.MoveBlockerCheckerDefaultImpl;
import gameframework.game.OverlapProcessor;
import gameframework.game.OverlapProcessorDefaultImpl;

public class GameLevelThree  extends GameLevelDefaultImpl{
	Canvas canvas;

	/* 1 - walls
	 * 5 - empty
	 * 6 - sword
	 * 7 - teleportHole
	 * 8 - checkpoint
	 */
	static int[][] tab = { 
		 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1 , 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1   },
		    { 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 1,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5 , 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,1  },
			{ 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5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5, 5,5,5,5, 5,5,5,5, 5,5,5,5 , 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,1  },
			{ 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5 , 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,5, 5,5,5,1  },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1 , 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1  }};

	public static final int SPRITE_SIZE = 16;
	public static final int NUMBER_OF_MONSTER = 2;

	@Override
	protected void init() {
		OverlapProcessor overlapProcessor = new OverlapProcessorDefaultImpl();

		MoveBlockerChecker moveBlockerChecker = new MoveBlockerCheckerDefaultImpl();
		moveBlockerChecker.setMoveBlockerRules(new ArenaMoveBlockers());
		
		ArenaOverlapRules overlapRules = new ArenaOverlapRules(new Point(22 * SPRITE_SIZE, 1 * SPRITE_SIZE),
				new Point(5 * SPRITE_SIZE, 15 * SPRITE_SIZE), life[0], score[0], endOfGame, NUMBER_OF_MONSTER);
				
		overlapProcessor.setOverlapRules(overlapRules);
		
		universe = new GameUniverseDefaultImpl(moveBlockerChecker, overlapProcessor);
		overlapRules.setUniverse(universe);

		gameBoard = new GameUniverseViewPortDefaultImpl(canvas, universe);
		((CanvasDefaultImpl) canvas).setDrawingGameBoard(gameBoard);

		//Ajout des elements static dans l'univers
		for (int i = 0; i < 31; ++i) {
			for (int j = 0; j < 75; ++j) {
				if (tab[i][j] == 1) {
					universe.addGameEntity(new Wall(canvas, j * SPRITE_SIZE, i * SPRITE_SIZE));
				}
				if (tab[i][j] == 6) {
					universe.addGameEntity(new SwordItem(canvas, new Point(j * SPRITE_SIZE, i * SPRITE_SIZE)));
				}
				if (tab[i][j] == 7) {
					universe.addGameEntity(new CheckPoint(canvas, new Point(j * 16, i * 16)));
				}
			}
		}

		//Création du hero
		SoldierGame myHero = HeroMan.getInstance("Hero", canvas,  universe);

		myHero.setPosition(new Point(22 * SPRITE_SIZE, 1 * SPRITE_SIZE));
		universe.addGameEntity(myHero);
		myHero.setUniverse(universe);

		
		GameMovableDriverDefaultImpl monsterDriv = new MonsterMovableDriver();
		MoveStrategyRandom ranStr = new MoveStrategyRandom();	
		
		monsterDriv.setStrategy(ranStr);
		monsterDriv.setmoveBlockerChecker(moveBlockerChecker);
		
		//Composite
		AgeFactory age = new ArenaAgeFactory();
		EntityFactory EntityFact = new EntityFactory();
		ArmedUnitSquad monsterSquad = new ArmedUnitSquad(age, "MonstersLVL3");
		
		//Création des monstres
		ArmedUnitSoldier monster1, monster2,monster3;
		
		monster1 = EntityFact.getWolves(age, "simple", "Wolf1", canvas);
		monster2 = EntityFact.getWolves(age, "simple", "Wolf2", canvas);
		monster3 = EntityFact.getWolves(age, "simple", "Wolf3", canvas);
		monster1.setPosition(new Point(5 * SPRITE_SIZE, 17 * SPRITE_SIZE));
		monster2.setPosition(new Point(5 * SPRITE_SIZE, 12 * SPRITE_SIZE));
		monster3.setPosition(new Point(8* SPRITE_SIZE, 12 * SPRITE_SIZE));

		monsterSquad.setPosition(new Point(5 * SPRITE_SIZE, 12 * SPRITE_SIZE));
		monsterSquad.addUnit(monster1);
		monsterSquad.addUnit(monster2);		
		
		monsterSquad.setPosition(new Point(5 * SPRITE_SIZE, 15 * SPRITE_SIZE));
		universe.addGameEntity(monster3);
		universe.addGameEntity(monster2);
		monster1.setDriver(monsterDriv);
		monster2.setDriver(monsterDriv);
		monster3.setDriver(monsterDriv);
	}

	public GameLevelThree(Game g) {
		super(g);
		canvas = g.getCanvas();
	}
}
